export default {
	namespaced: true,
	state() {
		return {
			address: JSON.parse(uni.getStorageSync('address') || 'null'),
			token: uni.getStorageSync('token'),
			//用户信息
			userInfo: JSON.parse(uni.getStorageSync('userInfo') || '{}'),
		}
	},
	mutations: {
		// 修改token
		settoken(state) {
			state.token = ''
			this.commit('user/settokenStore')
		},
		settokenStore(state) {
			uni.setStorageSync('token', state.token)
		},
		// 更新token
		updateToken(state, token) {
			state.token = token
			this.commit('user/saveToken')
		},
		saveToken(state) {
			uni.setStorageSync('token', state.token)
		},
		updateAddress(state, address) {
			state.address = address
			this.commit('user/saveAddressToStorage')
		},
		saveAddressToStorage(state) {
			uni.setStorageSync('address', JSON.stringify(state.address))
		}, //更新用户信息
		updateUserInfo(state, userInfo) {
			state.userInfo = userInfo
			this.commit('user/saveUserInfoToStorage')
		},
		saveUserInfoToStorage(state) {
			uni.setStorageSync('userInfo', JSON.stringify(state.userInfo))
		}
	},
	getters: {
		addressStr(state) {
			if (!state.address) return ''
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address
				.detailInfo
		}
	}
}
